//
//  ServiceManager.m
//  CarService
//
//  Created by Nimo.Yu on 15/1/30.
//  Copyright (c) 2015年 lexingsoft. All rights reserved.
//

#import "ServiceManager.h"

@implementation ServiceManager

+ (void)changeHostToQA{
    [DataManager sharedInstance].qaHost=@"http://120.25.195.84";
}

// 获取使用实例
+ (instancetype )sharedInstance
{
    static ServiceManager *sharedInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedInstance = [[super alloc] init];
    });
    return sharedInstance;
}

// 上传图片
+ (void) uploadImage:(UIImage *)image
             success:(void (^)(id dataObject))success
             failure:(void (^)())failure
{   ///publicusers/:userId/avatar
    
    NSString *path = [NSString stringWithFormat:@"/upload/testUpload.do"];
    NSData *data=UIImageJPEGRepresentation(image, 1.0);
//    NSData *keyData=[@"files=" dataUsingEncoding:NSUTF8StringEncoding];
//    NSMutableData *mutableData=[NSMutableData dataWithData:keyData];
//    [mutableData appendData:data];
    
    //    NSDictionary *parameterDict = @{@"files":data,
    //                                    };
    [NetworkClient postUploadRequest:path parameters:nil NeedPrompt:YES constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        //        NSError *error=nil;
        //        if(![formData appendPartWithFileURL:filePath name:@"files" error:&error])
        //        {
        //            DLog(@"error:%@",error.description);
        //        }
        [formData appendPartWithFileData:data name:@"imageFile" fileName:@"avatar.jpeg" mimeType:@"image/jpeg"];
        //        [formData appendPartWithFormData:data name:@"files"];
        //        [formData appendPartWithHeaders:nil body:mutableData];
    } progressBlock:^(long long sentBytes, long long needSendBytes) {
        DLog(@"sentBytes:%lld,needSendBytes:%lld",sentBytes,needSendBytes);
    } success:^(id dataObject) {
        success(dataObject);
    } failure:^(id dataObject) {
        failure();
    }];
}
@end
